﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace MetaTracker.Converters
{
    public class NullLongToNAConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return "N/A";

            string rv = "";
            try
            {
                var x = long.Parse(value.ToString());

                rv = x.ToString();

            }
            catch (Exception)
            {
                return "N/A";
            }
            return rv;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

    public class NullDoubleToNAConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return "N/A";

            double rv;
            try
            {
                var x = double.Parse(value.ToString());

                rv = x;

            }
            catch (Exception)
            {
                return "N/A";
            }
            return rv;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }


}
